      REAL*8 FUNCTION ERTROT(TSEC50,KPRECES)
      IMPLICIT REAL*8 (A-H,O-Z)
C
C  THIS ROUTINE GIVES THE EARTH ROTATION RATE.
C
C  THE ROTATION RATE IS DEFINED AS TWOPI DIVIDED BY THE NUMBER OF
C  SECONDS BETWEEN SUCCESSIVE CROSSINGS OF THE X-AXIS BY A GIVEN 
C  MERIDIAN ON THE ROTATING EARTH.
C
C
C  VARIABLE  DIM  TYPE I/O  DESCRIPTION
C  --------  ---  ---- ---  -----------
C
C  TSEC50     1   R*8   I   SECONDS SINCE 1/1/1950, 0.0 HRS. UT.
C
C                           NOT USED. PRESENT HERE TO ALLOW FOR FUTURE
C                           EXPANSION OF THE ROUTINE TO INCLUDE SLOWING
C                           OF THE RATE AND, IN THE CASE OF A SYSTEM
C                           WITH A PRECESSING X-AXIS, A TIME DEPENDENT
C                           PRECESSION RATE.
C
C                           HENCE: ONLY TWO VALUES ARE NOW POSSIBLE:
C                                  ONE FOR PRECESSING X-AXIS
C                                  ONE FOR FIXED X-AXIS
C
C  KPRECES    1   I*4   I   FLAG INDICATING WHETHER THE X-AXIS IS
C                           PRECESSING OR NOT.
C                           = 0, NOT PRECESSING(EX: MEAN OF 1950.0)
C                           = OTHERWISE, PRECESSING. MEAN OF DATE.
C
C  ERTROT     1    R*8  O   ROTATION RATE RETURNED AS THE FUNCTION
C                           VALUE. RAD/SEC.
C
C********************************************************************
C
C  CODED BY C PETRUZZO 10/82
C      MODIFIED.......
C           CJP. 6/83. REPLACED METHOD OF ASSIGNING RATE FOR A FIXED
C                      X-AXIS.
C
C********************************************************************
C
      INTEGER INIT/1/
      REAL*8 TWOPI/ 6.283185307179586D0 /
      REAL*8 DEGRAD/ 57.29577951308232D0 /
      REAL*8 ROTMTX(3,3),SECDAY/86400.D0/
C
      IBUG=0
      LUBUG=6
C
      IF(INIT.EQ.1) THEN
        INIT=0
C
C       SET NUMBER OF SECONDS IN A SIDEREAL DAY.
C       SIDEREAL DAY= TIME BETWEEN SUCCESSIVE TRANSITS OF
C       THE PRECESSING EQUINOX BY AN EARTH'S MERIDIAN.
C       ONE SIDEREAL DAY= 23 HR, 56 MIN, 4.09054 SEC; SOURCE IS
C       ASTRONOMICAL ALMANAC, 1983, PAGE L-7.
        SIDDAY=23.D0*3600.D0 + 56.D0*60.D0 + 4.09054D0
C
C       COMPUTE EARTH ROTATION RATE FOR PRECESSING X-AXIS(RAD/SEC).
        OMEGAP=TWOPI/SIDDAY
C
C       COMPUTE THE ROTATION RATE FOR A FIXED X-AXIS(RAD/SEC).
        TDIFF=SECDAY*365.25D0   ! 1 YEAR 
        RARATE=PRECES50(TDIFF,1)/TDIFF   ! RACN PRECESSION, RAD/SEC.
        OMEGAF=OMEGAP+RARATE
C
        IF(IBUG.EQ.1) THEN
          WRITE(LUBUG,1001) SIDDAY,OMEGAP,OMEGAP*DEGRAD,
     *          RARATE*DEGRAD*3600.D0*86400.D0*365.25D0,
     *          RARATE*DEGRAD,OMEGAF,OMEGAF*DEGRAD
 1001     FORMAT(/,' ERTROT DEBUG.'/,
     *     '  SIDDAY(SEC)=',G25.16/,
     *     '  OMEGAP(RAD/SEC, DEG/SEC)=',2G25.16/,
     *     '  RARATE(ARCSEC/YR)=',G25.16/,'  RARATE(DEG/SEC)=',G25.16/,
     *     '  OMEGAF(RAD/SEC, DEG/SEC)=',2G25.16)
          END IF
        END IF
C
      IF(KPRECES.EQ.0) THEN
        ERTROT=OMEGAF
      ELSE
        ERTROT=OMEGAP
        END IF
C
      RETURN
      END
